import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_learn/app/modules/navigation_demo/nested_navigation/modules/nested_navigation1/bindings/nested_navigation1_binding.dart';
import 'package:getx_learn/app/modules/navigation_demo/nested_navigation/modules/nested_navigation1/views/nested_navigation1_view.dart';
import 'package:getx_learn/app/modules/navigation_demo/nested_navigation/modules/nested_navigation2/bindings/nested_navigation2_binding.dart';
import 'package:getx_learn/app/modules/navigation_demo/nested_navigation/modules/nested_navigation2/views/nested_navigation2_view.dart';
import 'package:getx_learn/app/modules/navigation_demo/nested_navigation/modules/nested_navigation3/bindings/nested_navigation3_binding.dart';
import 'package:getx_learn/app/modules/navigation_demo/nested_navigation/modules/nested_navigation3/views/nested_navigation3_view.dart';
import 'package:getx_learn/app/routes/app_pages.dart';

class NestedNavigationController extends GetxController {
  //TODO: Implement NestedNavigationController

  static NestedNavigationController get to => Get.find();

  var currentIndex = 0.obs;

  final pages = <String>[
    Routes.NESTED_NAVIGATION1,
    Routes.NESTED_NAVIGATION2,
    Routes.NESTED_NAVIGATION3
  ];

  // final pages = <String>['/list', '/detail', '/login'];

  @override
  void onInit() {
    super.onInit();
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }

  void changePage(int index) {
    currentIndex.value = index;
    Get.toNamed(pages[index], id: 1);
  }

  Route? onGenerateRoute(RouteSettings settings) {
    // 嵌套路由 start
    // static GetPage NESTED_NAVIGATION1 = GetPage(
    //   name: _Paths.NESTED_NAVIGATION1,
    //   page: () => const NestedNavigation1View(),
    //   binding: NestedNavigation1Binding(),
    // );
    // static GetPage NESTED_NAVIGATION2 = GetPage(
    //   name: _Paths.NESTED_NAVIGATION2,
    //   page: () => const NestedNavigation2View(),
    //   binding: NestedNavigation2Binding(),
    // );
    // static GetPage NESTED_NAVIGATION3 = GetPage(
    //   name: _Paths.NESTED_NAVIGATION3,
    //   page: () => const NestedNavigation3View(),
    //   binding: NestedNavigation3Binding(),
    // );

    // 嵌套路由 end

    print("route = ${settings.name}\n");

    if (settings.name == Routes.NESTED_NAVIGATION1)
      // if (settings.name == '/login')
      return GetPageRoute(
        settings: settings,
        page: () => NestedNavigation1View(),
        binding: NestedNavigation1Binding(),
        transition: Transition.topLevel,
      );
    else if (settings.name == Routes.NESTED_NAVIGATION2)
      // else if (settings.name == '/list')
      return GetPageRoute(
        settings: settings,
        page: () => NestedNavigation2View(),
        binding: NestedNavigation2Binding(),
        transition: Transition.rightToLeftWithFade,
      );
    else if (settings.name == Routes.NESTED_NAVIGATION3)
      // else if (settings.name == '/detail')
      return GetPageRoute(
        settings: settings,
        page: () => NestedNavigation3View(),
        binding: NestedNavigation3Binding(),
        transition: Transition.fadeIn,
      );

    return null;
  }
}
